let path = require('path')
let HtmlWebpackPlugin = require('html-webpack-plugin')
let CleanWebpackPlugin = require('clean-webpack-plugin')
let CopyWebpackPlugin = require('copy-webpack-plugin')
let webpack = require('webpack')
// webpack 小插件
// 1.cleanWebpackPlugin  删除文件夹
// 2. copyWebpackPlugin 拷贝文件
// 3. bannerPlugin 内置的 版权申明 插到每个文件
module.exports = {
  mode: 'production',
  entry: {
    home: './src/source.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      }
    ]
  },
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, 'dist')
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',
      filename: 'index.html'
    }),
    new CleanWebpackPlugin('./dist'),
    new CopyWebpackPlugin([
      {from: './doc', to: './'}
    ]),
    new webpack.BannerPlugin('make 2019 by fbk')
  ]
}